package cn.itsource.user.controller;

import cn.itsource.user.domain.vo.UserVo;
import cn.itsource.user.service.IWxUserService;
import cn.itsource.utils.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/wxUser")
public class WxUserController {

    @Autowired
    private IWxUserService wxUserService;



    /*
        code	"123546"
        password	"123"
        passwordRepeat	"123"
        phone	"15008495702"
     */

    @RequestMapping("/code")
    public AjaxResult register(String code){
        //保存数据
        try {
            return wxUserService.getAccessToken(code);
            //return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage(e.getMessage());
        }
    }

    @PostMapping("/binder")
    public AjaxResult register(@RequestBody UserVo userVo){
        //保存数据
        try {
            return  wxUserService.binder(userVo);
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setSuccess(false).setMessage(e.getMessage());
        }
    }

}
